<template>
  <div>
    <el-form :model="formItem" label-width="80px" size="mini" class="form-view">
      <el-row>
        <el-col :span="12">
          <el-form-item label="工单标题" prop="title">
            {{ formItem.title }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="到货日期" prop="receiveDate">
            {{ formItem.receiveDate }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库类型" prop="receiveDate">
            {{ formItem.categories === '1' ? '非消耗品' : '消耗品' }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库合同" prop="contractName">
            {{ formItem.contractName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="购置日期" prop="purchaseDate">
            {{ formItem.purchaseDate }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="存放位置" prop="locationName">
            {{ formItem.locationName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="综合管理部" prop="comprehensive">
            {{ formItem.comprehensive === true ? '是' :'否' }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注信息" prop="remark">
            {{ formItem.remark }}
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="资产明细">
            <PageableTable
              :columns="assetColumns"
              :loading="false"
              :table-height="240"
              :data="formItem.assetList"
              :disable-pageable="true"
              class="fixed-table-table"
            >
              <el-table-column
                label="序号"
                type="index"
                width="50"
              />
              <el-table-column v-for="column in assetColumns" :key="column.key" :label="column.title" :prop="column.key" :sortable="column.sortable">
                <template slot-scope="scope">
                  <column-render :render="column.render" :row="scope.row" :column="column" />
                </template>
              </el-table-column>
            </PageableTable>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { detail } from '@neu/dcam-ui/api/arrival'
import PageableTable from '@neu/biz-core/components/PageableTable'
import { formatDate } from '@neu/biz-core/utils/utils'
const formItem = {
  title: '',
  receiveDate: '',
  contractCode: '',
  contractName: '',
  locationName: '',
  remark: '',
  annex: [],
  arrivalCount: [],
  arrivalDetail: []
}
export default {
  components: {
    PageableTable
  },
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      formItem: {
        ...formItem
      },
      // 资产列定义
      assetColumns: [
        { title: '类型名称', width: 100, key: 'typeName' },
        { title: '规格型号', key: 'specification' },
        { title: '计量单位', key: 'measureUnit' },
        { title: '品牌', key: 'brand' },
        { title: '序列号', width: 100, key: 'serialnumber',
          render: (h, params) => {
            return params.row.edit ? (
              <el-input size='mini' v-model={params.row.serialnumber} placeholder='序列号' />
            ) : h('span', params.row.serialnumber)
          }
        },
        { title: '位置', width: 160, key: 'locationName', render: (h, params) => {
          return params.row.edit ? (
            <treeselect v-model={params.row.location} multiple={false} options={this.availableLocations} placeholder='位置'/>
          ) : h('span', params.row.locationName)
        } },
        { title: '使用期限', width: 80, key: 'usePeriod',
          render: (h, params) => {
            return params.row.edit ? (
              <el-input size='mini' v-model={params.row.usePeriod} placeholder='' />
            ) : h('span', params.row.usePeriod)
          } },
        { title: '维保开始', width: 148, key: 'maintenanceStartTime',
          render: (h, params) => {
            return params.row.edit ? (
              <el-date-picker size='mini' v-model={params.row.maintenanceStartTime} type='date' align='right' />
            ) : h('span', formatDate(params.row.maintenanceStartTime, 'YYYY-MM-DD'))
          } },
        { title: '维保结束', width: 148, key: 'maintenanceEndTime',

          render: (h, params) => {
            return params.row.edit ? (
              <el-date-picker size='mini' v-model={params.row.maintenanceEndTime} type='date' align='right' />
            ) : h('span', formatDate(params.row.maintenanceEndTime, 'YYYY-MM-DD'))
          } }
      ]
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          this.formItem = {
            ...response.data
          }
          this.formItem.receiveDate = formatDate(this.formItem.receiveDate, 'YYYY-MM-DD')
          this.formItem.purchaseDate = formatDate(this.formItem.purchaseDate, 'YYYY-MM-DD')
        })
      } else {
        this.formItem = {
          ...formItem
        }
      }
    }
  }
}
</script>
